<template>
	<view>
		<view class="content-tabs">
			<button @click="activeIndex = 0;goPage('/pages/referralDetails/referralDetails')" :class="activeIndex == 0 ? 'active' : ''">患者信息</button>
			<button @click="activeIndex = 1;goPage('/pages/referralProcess/referralProcess')" :class="activeIndex == 1 ? 'active' : ''">转诊流程</button>
			<button @click="activeIndex = 2;goPage('/subPackages/pages/chat/main')" :class="activeIndex == 2 ? 'active' : ''">转诊交流记录</button>
			<button @click="activeIndex = 3;goPage('/subPackages/pages/chat/main')" :class="activeIndex == 3 ? 'active' : ''">床位预约信息</button>
		</view>
		<ul class="list-box">
			<li v-for="item in detailData">
				<p>{{item.referral_status_data_text}}</p>
				<p>{{formatTimestamp(item.updatetime)}}</p>
			</li>
		</ul>
	</view>
</template>

<script>
import { genTestUserSig } from "subPackages/static/utils/GenerateTestUserSig.js";
	export default {
		data() {
			return {
				detailData:{}
			}
		},
		onLoad(option) {
			console.log(option);
			this.goImpage(option.id)
		},
		methods: {
			formatTimestamp(timestamp) {
			    // 创建一个 Date 对象，将时间戳作为参数传入
			    const date = new Date(timestamp*1000);
			    
			    // 使用 Date 对象的方法获取年、月、日、小时、分钟和秒
			    const year = date.getFullYear();
			    const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1，并确保两位数格式
			    const day = String(date.getDate()).padStart(2, '0'); // 确保两位数格式
			    const hours = String(date.getHours()).padStart(2, '0'); // 确保两位数格式
			    const minutes = String(date.getMinutes()).padStart(2, '0'); // 确保两位数格式
			    const seconds = String(date.getSeconds()).padStart(2, '0'); // 确保两位数格式
			    
			    // 拼接成所需的时间字符串格式
			    const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			    
			    // 返回格式化后的时间字符串
			    return formattedTime;
			},
			goImpage(optionId){
				let that = this;
					uni.getStorage({
						key: 'userInfo',
						success: function (res) {
							uni.request({
								url:that.$apiUrl+'api/referral/flow',
								method:"GET",
								header:{'token':JSON.parse(res.data).token},
								data:{referral_id:optionId}
							}).then(res2=>{
								that.detailData = res2[1].data.data || {};
							});
						}
					
				})
			},
			goPage(path){
				if(path == '/subPackages/pages/chat/main'){
					this.$store.dispatch('checkoutConversation',`GROUP${this.detailData.coded}`)
					uni.navigateTo({
						url:"/subPackages/pages/chat/main"
					})
				}else{
					uni.navigateTo({
						url:path+'?id='+this.detailData.id
					})
				}
				
			},
			goImpage(item) {
			  let that = this;
			  uni.getStorage({
			    key: "userInfo",
			    success: function (res) {
			      const userID = JSON.parse(res.data).tencent_id;
			      wx.$app
			        .login({
			          userID: String(JSON.parse(res.data).tencent_id),
			          userSig: genTestUserSig(String(JSON.parse(res.data).tencent_id))
			            .userSig,
			        })
			        .then(() => {
			          setTimeout(function () {
			            that.$store.dispatch(
			              "checkoutConversation",
			              `GROUP${item.coded}`
			            );
			            uni.navigateTo({
			              url: "/subPackages/pages/chat/main",
			            });
			          }, 1000);
			        });
			    },
			  });
			}
		}
	}
</script>

<style scoped>
	.content-tabs{
		display: flex;
		padding:32rpx 0;
		margin:0 24rpx;
		width:calc(100% - 48rpx);
		overflow-y: auto;
	}
	.content-tabs>button{
		width:160rpx;
		height:56rpx;
		font-size:24rpx;
		background:#fff;
		padding:0;
	}
	.content-tabs>button:not(:first-child){
		margin-left:16rpx;
	}
	.active{
		background:#3c8af3!important;
		color:#fff!important;
	}
.list-box{
	padding:20rpx;
}
</style>
